class LoadSDK {
  load(src: string) {
    return new Promise((resolve, reject) => {
      const script = document.createElement("script");
      script.src = src;
      script.onload = () => resolve(void 0);
      script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
      document.body.appendChild(script);
    });
  }
  /**
   * 加载微信 SDK.
   */
  async WXSDK() {
    return await this.load("https://res.wx.qq.com/open/js/jweixin-1.6.0.js");
  }

  /**
   * 加载支付宝 SDK.
   */
  async AliSDK() {
    return await this.load(
      "https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"
    );
  }

  /**
   * 加载云闪付 SDK.
   */
  async unionSDK() {
    return await this.load("https://open.95516.com/s/open/js/upsdk.js");
  }
}

export const loadSDK = new LoadSDK();
